package com.cmcc.pcap.packet.util.pfcpUtile;

import com.cmcc.packet.entity.PfcpEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class CauseUtil implements PfcpTypeUtil {
    private static Logger logger = LogManager.getLogger(CauseUtil.class);
    int CauseValue;

    @Override
    public PfcpEntity.InformationElement analysisIe(byte[] sub_payload) {
        PfcpEntity.InformationElement peie = new PfcpEntity.InformationElement();
        peie.setType(((sub_payload[0] & 0xff) << 8) + (sub_payload[1] & 0xff));
        peie.setLength(((sub_payload[2] & 0xff) << 8) + (sub_payload[3] & 0xff));
        Map<String, String> dataMap = new HashMap<>();
        if(sub_payload.length >= 9) {
            if((sub_payload[4] & 0xff) == 1) {
                dataMap.put("CauseValue", "success");
            }else {
                dataMap.put("CauseValue", "fail");
            }
        }else {
            logger.error("Inadequate TLV length: %d", sub_payload.length);
        }
        return peie;
    }
}
